<template>
  <transition :name="transitionName">
    <div v-if="visible" class="drawer-wrapper">
      <div class="drawer-mask" @click="handleClose"></div>
      <div class="drawer-container" :class="[`drawer-${placement}`]" :style="{ width: width }">
        <div class="drawer-header">
          <h3 class="drawer-title">{{ title }}</h3>
          <button class="drawer-close" @click="handleClose">&times;</button>
        </div>
        <div class="drawer-body">
          <slot></slot>
        </div>
        <div class="drawer-footer" v-if="$slots.footer">
          <slot name="footer"></slot>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: 'FeedbackDrawer',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    },
    placement: {
      type: String,
      default: 'right',
      validator: value => ['left', 'right', 'top', 'bottom'].includes(value)
    },
    width: {
      type: String,
      default: '300px'
    }
  },
  computed: {
    transitionName() {
      return `drawer-${this.placement}`
    }
  },
  methods: {
    handleClose() {
      this.$emit('update:visible', false)
      this.$emit('close')
    }
  }
}
</script>

<style scoped>
.drawer-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
}

.drawer-mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

.drawer-container {
  position: absolute;
  background: white;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  height: 100%;
}

.drawer-right {
  top: 0;
  right: 0;
}

.drawer-left {
  top: 0;
  left: 0;
}

.drawer-top {
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
}

.drawer-bottom {
  bottom: 0;
  left: 0;
  width: 100%;
  height: auto;
}

.drawer-header {
  padding: 15px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-title {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
}

.drawer-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
}

.drawer-body {
  padding: 20px;
  height: calc(100% - 120px);
  overflow-y: auto;
}

.drawer-footer {
  padding: 10px 20px;
  border-top: 1px solid #eee;
  text-align: right;
}

.drawer-right-enter-active,
.drawer-right-leave-active,
.drawer-left-enter-active,
.drawer-left-leave-active,
.drawer-top-enter-active,
.drawer-top-leave-active,
.drawer-bottom-enter-active,
.drawer-bottom-leave-active {
  transition: all 0.3s ease;
}

.drawer-right-enter,
.drawer-right-leave-to {
  transform: translateX(100%);
}

.drawer-left-enter,
.drawer-left-leave-to {
  transform: translateX(-100%);
}

.drawer-top-enter,
.drawer-top-leave-to {
  transform: translateY(-100%);
}

.drawer-bottom-enter,
.drawer-bottom-leave-to {
  transform: translateY(100%);
}
</style> 